package source;

import bean.Order;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 *
 * 预定义Source
 * 1. env.readTextFile   (本地、hdfs文件、文件夹、压缩文件)
 * 2. env.socketTextStream("url", port)
 * 自定义Source
 * 1. SourceFunction:非并行数据源(并行度只能=1)
 * 2. RichSourceFunction:多功能非并行数据源(并行度只能=1)
 * 3. ParallelSourceFunction:并行数据源(并行度能够>=1)
 * 4. RichParallelSourceFunction:多功能并行数据源(并行度能够>=1)--后续学习的Kafka数据源使用的就是该接口
 *
 */

public class SourceDemo {

    public static void main(String[] args) throws Exception {

        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        // 1 预定义source： env.readTextFile(本地、hdfs文件、文件夹、压缩文件)
        // DataStreamSource<String> textDS = env.readTextFile("");


        // 2 从kafka读source
//        Properties properties = new Properties();
//        properties.setProperty("bootstrap.servers", "localhost:9092");
//        properties.setProperty("group.id", "consumer-group");
//        properties.setProperty("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
//        properties.setProperty("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
//        properties.setProperty("auto.offset.reset", "latest");
//        DataStream<String> dataStream = env.addSource( new FlinkKafkaConsumer011<String>("sensor", new SimpleStringSchema(), properties));


        // 3 自定义source: 每隔1秒随机生成一条订单信息(订单ID、用户ID、订单金额、时间戳)
        DataStreamSource<Order> orderDS = env.addSource(new MyOrderSource());


        orderDS.print();
        env.execute();

    }


}
